/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sig.visorcliente.form;

import com.sig.utilerias.entity.EntityManagerFactory;
import com.six.dto.GcliCliente;
import com.six.dto.GcliHistoriaClinica;
import com.six.dto.GcliHistoriaClinicaPK;
import com.six.dto.GcliInfProblemaMedico;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import javax.swing.AbstractListModel;
import javax.swing.JComboBox;
import javax.swing.JTextArea;
import javax.swing.MutableComboBoxModel;

/**
 *
 * @author sigfrido
 */
public class EditorObservacionesForm extends javax.swing.JPanel {

    private GcliHistoriaClinicaPK pk;

    /**
     * Creates new form HistoriaClinicaForm
     */
    public EditorObservacionesForm(GcliHistoriaClinicaPK pk) {
        initComponents();
        EntityManager em = EntityManagerFactory.getEntityManager();
        GcliHistoriaClinica historiaClinica = em.find(GcliHistoriaClinica.class, pk);
        jtaObservaciones.setText(historiaClinica.getObservaciones());
        this.pk = pk;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtaObservaciones = new javax.swing.JTextArea();

        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(EditorObservacionesForm.class, "EditorObservacionesForm.jLabel1.text")); // NOI18N
        jLabel1.setPreferredSize(new java.awt.Dimension(120, 15));

        jtaObservaciones.setColumns(20);
        jtaObservaciones.setRows(5);
        jScrollPane1.setViewportView(jtaObservaciones);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 273, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 130, Short.MAX_VALUE)))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jtaObservaciones;
    // End of variables declaration//GEN-END:variables

    private class MyModel extends AbstractListModel<GcliInfProblemaMedico> implements MutableComboBoxModel<GcliInfProblemaMedico>, Serializable {

        private final List<GcliInfProblemaMedico> infProblemaMedicos = new ArrayList<GcliInfProblemaMedico>();
        private GcliInfProblemaMedico problemaMedico = null;

        public MyModel() {
        }

        public MyModel(List<GcliInfProblemaMedico> infProblemaMedicos) {
            this.infProblemaMedicos.clear();
            this.infProblemaMedicos.addAll(infProblemaMedicos);
        }

        public void addElements(List<GcliInfProblemaMedico> infProblemaMedicos) {
            this.infProblemaMedicos.clear();
            this.infProblemaMedicos.addAll(infProblemaMedicos);
        }

        @Override
        public int getSize() {
            return infProblemaMedicos.size();
        }

        @Override
        public GcliInfProblemaMedico getElementAt(int index) {
            return infProblemaMedicos.get(index);
        }

        @Override
        public void addElement(GcliInfProblemaMedico item) {
            this.infProblemaMedicos.add(item);
        }

        @Override
        public void removeElement(Object obj) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void insertElementAt(GcliInfProblemaMedico item, int index) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void removeElementAt(int index) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        @Override
        public void setSelectedItem(Object anObject) {
            if ((problemaMedico != null && problemaMedico.getIdProblema().intValue() != ((GcliInfProblemaMedico) anObject).getIdProblema().intValue())
                    || problemaMedico == null && anObject != null) {
                problemaMedico = (GcliInfProblemaMedico) anObject;
                fireContentsChanged(this, -1, -1);
            }
        }

        @Override
        public Object getSelectedItem() {
            return problemaMedico;
        }
    }

    public JTextArea getJtaObservaciones() {
        return jtaObservaciones;
    }
}
